﻿using site.Models;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web.Mvc;

namespace site.Controllers
{
    public class StudyController : Controller
    {
        
        public ActionResult Index()
        {
            var study = new Study();

            return View(study);
        }

        [HttpPost]
        public ActionResult Index(Study _study)
        {
            /*
            if (string.IsNullOrEmpty(_study.Title))
            {
                ModelState.AddModelError("","Title empty");
            }

            if (string.IsNullOrEmpty(_study.Title))
            {
                ModelState.AddModelError("Title", "*");
            }
            */


            if (ModelState.IsValid)
            {
                return View("Result", _study);
            }

            return View(_study);
        }


        public ActionResult Result(Study _study)
        { 
            return View(_study);
        }

        /* created to use on remote validation */
        public ActionResult TitleUnique(string title)
        {
            var fakeTitleList = new Collection<string> {"ASP.NET MVC", "C#", "Windows Store Apps", "Janynne"};


            return Json(fakeTitleList.All(x => x.ToLower() != title.ToLower()), JsonRequestBehavior.AllowGet);
        }
    }
} 
